﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Mvc;

namespace ERPStore.Web.Start
{
	public static class WebApiConfig
	{
		public static void Register(HttpConfiguration config)
		{
			// Web API routes
			config.MapHttpAttributeRoutes();

			config.Routes.MapHttpRoute(
				"AccountApi"
				, "api/account/{action}/{id}"
				, new { controller = "AccountApi", action = "Ping", id = UrlParameter.Optional }
				);
			config.Routes.MapHttpRoute(
				"AdminApi"
				, "api/admin/{action}/{*id}"
				, new { controller = "AdminApi", action = "Ping", id = UrlParameter.Optional }
				);
			config.Routes.MapHttpRoute(
				"EmailerApi"
				, "api/emailer/{action}/{id}"
				, new { controller = "EmailerApi", action = "Ping", id = UrlParameter.Optional }
				);
			config.Routes.MapHttpRoute(
				"EmailTemplateApi"
				, "api/emailtemplate/{action}/{id}"
				, new { controller = "EmailTemplateApi", action = "Ping", id = UrlParameter.Optional }
				);
			config.Routes.MapHttpRoute(
				"CatalogApi"
				, "api/catalog/{action}/{*id}"
				, new { controller = "CatalogApi", action = "Ping", id = UrlParameter.Optional }
				);
			config.Routes.MapHttpRoute(
				"CheckoutApi"
				, "api/checkout/{action}/{id}"
				, new { controller = "CheckoutApi", action = "Ping", id = UrlParameter.Optional }
				);
			config.Routes.MapHttpRoute(
				"MediaApi"
				, "api/media/{action}/{*id}"
				, new { controller = "MediaApi", action = "Ping", id = UrlParameter.Optional }
				);
			config.Routes.MapHttpRoute(
				"StoreApi"
				, "api/store/{action}/{*id}"
				, new { controller = "StoreApi", action = "Ping", id = UrlParameter.Optional }
				);

			// Always last route
			config.Routes.MapHttpRoute(
				"API"
				, "api/{controller}/{action}/{id}"
				, new { action = RouteParameter.Optional, id = RouteParameter.Optional }
				);

			GlobalConfiguration.Configuration.Logger.Info("WebApi services routes configured");
		}
	}
}
